package com.giser.testapp.lib;

import android.util.Xml;

import org.xmlpull.v1.XmlPullParser;

import java.io.File;
import java.io.FileInputStream;

/**
 * Created by lss on 2017/11/14.
 */

public class TClass {
    /**
     * 获得文件路径
     * @return
     */
    public static File getCompanyDir() {
        File file = new File(getStorageDirectory().getAbsolutePath() + "/WebViewApp");
        file.mkdirs();
        return file;
    }
    public static File getStorageDirectory() {
        return android.os.Environment.getExternalStorageDirectory();
    }

    /**
     * 读写webViewConfig.xml
     * @return
     */
    public static String getWebViewUrl(){
        String name = "";
        try {
            File path=new File(getCompanyDir()+"/webViewConfig.xml");
            FileInputStream fis = new FileInputStream(path);

            // 获得pull解析器对象
            XmlPullParser parser = Xml.newPullParser();
            // 指定解析的文件和编码格式
            parser.setInput(fis, "utf-8");

            int eventType = parser.getEventType(); // 获得事件类型
            while (eventType != XmlPullParser.END_DOCUMENT) {
                String tagName = parser.getName(); // 获得当前节点的名称

                switch (eventType) {
                    case XmlPullParser.START_TAG: // 当前等于开始节点 <person>
                        if ("EnvApplication".equals(tagName)) { // <EnvApplication>
                        } else if ("url".equals(tagName)) { // <name>
                            name = parser.nextText();
                        }
                        break;
                    case XmlPullParser.END_TAG: // </persons>
                        break;
                    default:
                        break;
                }
                eventType = parser.next(); // 获得下一个事件类型
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally{

        }
        return name;
    }
}
